# 965 简单：单值二叉树

# Definition for a binary tree node.
# class HOT.TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
from collections import deque


class Solution:
    def isUnivalTree(self, root: HOT.TreeNode) -> bool:

        # 深度优先搜索
        # if not root:
        #     return True
        #
        # if root.left:
        #     if root.val != root.left.val or not self.isUnivalTree(root.left):
        #         return False
        #
        # if root.right:
        #     if root.val != root.right.val or not self.isUnivalTree(root.right):
        #         return False
        #
        # return True

        # 广度优先搜索
        if not root:
            return True
        q = deque()
        q.append(root)
        while q:
            cur = q.popleft()
            if cur.val != root.val:
                return False
            if cur.left:
                q.append(cur.left)
            if cur.right:
                q.append(cur.right)
        return True
